
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>节点创建追加</h2>
<script type="text/javascript">
    var ull=document.createElement('ul');
    var province=['辽宁','山东','浙江'];
    var city=['沈阳','济南','杭州'];
    for(var k in province){
        //1.创建li的元素节点
        var lii=document.createElement('li');
        //2.创建li内部文本节点
        var txt=document.createTextNode(province[k]);
        //给li节点设置属性
        lii.setAttribute('city',city[k]);
        lii.appendChild(txt);
        ull.appendChild(lii);
    }
    //给body追加ull节点
    document.getElementsByTagName('body')[0].appendChild(ull);

</script>
</body>
</html>